package com.pmsystem.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pmsystem.dao.ComplaintMapper;
import com.pmsystem.pojo.Complaint;
import com.pmsystem.util.BeanUtil;

@Service
public class ComplaintService {

	@Autowired
	private ComplaintMapper complaintMapper;

	/**
	 * 
	 * <p>Title: addComplaint</p >  
	 * <p>Description: 业主投诉</p >  
	 * @author 泽强
	 * @param complaint
	 * @return
	 */
	public boolean addComplaint(Complaint complaint) {
		int flag = complaintMapper.insertSelective(complaint);
		return flag != 0 ? true : false;
	}

	/**
	 * 
	 * <p>Title: findByUserId</p >  
	 * <p>Description: 根据userId查投诉</p >  
	 * @author 泽强
	 * @param userId
	 * @return
	 */
	public List<Complaint> findByUserId(int userId) {	
		return complaintMapper.findByUserId(userId);	
	}
	
	/**
	 * 
	 * <p>Title: findComplaint</p >  
	 * <p>Description: 按一定条件查询投诉，注意SQL语句</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	public List<Complaint> findComplaint(Map<String, Object> map) {
		Integer pageNo = (Integer) map.get("pageNo");
		Integer pageSize = (Integer) map.get("pageSize");
		if(pageNo!=null&&pageSize!=null) {
			int start = (pageNo - 1) * pageSize;
			map.put("start", start);
		}
		return complaintMapper.findComplaint(BeanUtil.mapToMapWithoutNull(map));
	}
	
	/**
	 * 
	 * <p>Title: updateComplaint</p >  
	 * <p>Description: 修改抱怨</p >  
	 * @author 泽强
	 * @param complaint
	 * @return
	 */
	public boolean updateComplaint(Complaint complaint) {
		int flag = complaintMapper.updateByPrimaryKeySelective(complaint);
		return flag != 0 ? true : false;
	}

}
